import { Controller } from 'egg';

class CommnetController extends Controller {
    /**
     * 根据解忧id获取评论列表
     */
    public async searchCommentById() {
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                assuage_grief_id: 'string',
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        let result = await ctx.service.commentService.searchCommentById(request.body);
        ctx.body = ctx.helper.responseSuccess('查询成功', result);
    }

    /**
     * 根据解忧id获取评论列表-后台
     */
    public async searchAdminCommentById() {
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                assuage_grief_id: 'string',
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        let result = await ctx.service.commentService.searchAdminCommentById(request.body);
        ctx.body = ctx.helper.responseSuccess('查询成功', result);
    }

    /**
     * 操作评论状态（1：解除屏蔽，2：屏蔽）
     */
    public async editCommentShield() {
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                comment_id: 'string',
                type: 'type'
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        await ctx.service.commentService.editCommentShield(request.body);
        ctx.body = ctx.helper.responseSuccess('操作成功');
    }

    /**
     * 评论回复
     */
    public async commentReply() {
        const { ctx, ctx: { request } } = this;
        try {
            ctx.validate({
                level: 'type',
                assuage_grief_id: 'string',
                user_id: 'string',
                comment_content: 'string',
                comment_status: 'type',
                be_comment_status: 'type'
            }, request.body)
        } catch (e) {
            ctx.body = ctx.helper.responseErrorParam(e.errors[0].message);
            return;
        }
        await ctx.service.commentService.commentReply(request.body);
        ctx.body = ctx.helper.responseSuccess('评论成功');
    }
}
export default CommnetController;